﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ECare.BUS.Workers;
using ECare.Client.templates;
using ECare.BUS.Data;
using ECare.BUS;

namespace ECare.Client.frms
{
    public partial class frmInInfoReadonly : frmInfo
    {
        public frmInInfoReadonly()
        {
            InitializeComponent();

            this.Load += frmInInfoReadonly_Load;
            this.IsCancel = false;
        }

        public bool IsCancel { get; set; }


        public SupplyInfo CurrentSupply { get; set; }
        void frmInInfoReadonly_Load(object sender, EventArgs e)
        {
            //throw new NotImplementedException();

            this.CurrentSupply = this.entity as SupplyInfo;
            if (this.CurrentSupply != null)
            {
                this.ucInInfo1.CurrentSupply = this.CurrentSupply;
                this.ucInInfo1.LoadInformation();

                this.ucInCheckInfo1.CurrentSupply = this.CurrentSupply;
                this.ucInCheckInfo1.LoadInformation();
            }

            //if (this.CurrentSupply.supply_checkstatus == CheckStatus.SpecialAcceptance
            //    || this.CurrentSupply.supply_checkstatus == CheckStatus.Qualitified
            //    )
            //{
            //    //enable deactive the 
            //    this.btnSave.Visible = true;
            //}
            //else
            //{
            //    this.btnSave.Visible = false;
            //}

            if (this.IsCancel)
            {
                //取消出库
                this.btnSave.Visible = true;
            }
            else
            {
                this.btnSave.Visible = false;
            }

        }

        private void eButton1_Click(object sender, EventArgs e)
        {
            var worker = new InReportBuilder();
            worker.CurrentSupplyInfo = this.CurrentSupply as SupplyInfo;
            worker.RunWorkerCompleted += worker_RunWorkerCompleted;
            worker.RunWorkerAsync();
        }
        void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            var frmprint = new frmPrint(); frmprint.file = e.Result as string;
            frmprint.ShowDialog();

        }

        public event EntitySavedHandler Deactived;
        private void btnSave_Click(object sender, EventArgs e)
        {
            var currentsupply = this.entity as SupplyInfo;

            var outcount = SupplyInfoHelper.GetSupplyDetails(currentsupply.supply_id);
            if (outcount > 0)
            {
                MessageBox.Show("已经出库,不能取消入库.", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (MessageBox.Show("是否取消这次入库?", "信息提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) ==
                DialogResult.No)
                return;

            SupplyInfoHelper.DeactiveStorage(currentsupply.supply_id);
            if (Deactived != null)
            {
                this.Deactived(currentsupply);
            }
            this.Close();



        }
    }
}
